package com.Listeners;


import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import com.Data.Follow;
import com.Data.Follow.onAddFollowerCompleted;
import com.Data.Follow.onDeleteFollowerCompleted;
import com.activities.ActivityProfileUser;
import com.shareup.R;


public class FollowButtonListener {

    public static class AddFollowerListener implements OnClickListener {

        private ActivityProfileUser ActivityUser;

        private final ImageView followB;

        private final int friendID;

        public AddFollowerListener(int friendID, ImageView followB) {

            super();
            this.friendID = friendID;
            this.followB = followB;

            followB.setBackgroundResource(R.drawable.selector_button_follow_add);
        }

        public AddFollowerListener(int friendID, ImageView followB,
                    ActivityProfileUser ActivityUser) {

            super();
            this.friendID = friendID;
            this.followB = followB;
            this.ActivityUser = ActivityUser;
            followB.setBackgroundResource(R.drawable.selector_button_follow_add);
        }

        @Override
        public void onClick(View v) {

            Log.e("as", "cliked");
            Follow fl = new Follow(friendID);
            fl.setCallbackAddFollow(new onAddFollowerCompleted() {

                @Override
                public void Completed() {

                    Log.e("as", "completed");
                    followB.setBackgroundResource(R.drawable.selector_button_follow_remove);
                    followB.setOnClickListener(new DeleteFollowerListener(friendID, followB, ActivityUser));
                    if (ActivityUser != null)
                        ActivityUser.updateFollowInfo(friendID);

                }
            });
            fl.execute(Follow.ACTION_ADD);
        }
    }

    public static class DeleteFollowerListener implements OnClickListener {

        private ActivityProfileUser ActivityUser;

        private final ImageView followB;

        private final int friendID;

        public DeleteFollowerListener(int fID, ImageView followB) {

            super();
            this.friendID = fID;
            this.followB = followB;
            followB.setBackgroundResource(R.drawable.selector_button_follow_remove);
        }

        public DeleteFollowerListener(int fID, ImageView followB,
                    ActivityProfileUser ActivityUser) {

            super();
            this.friendID = fID;
            this.followB = followB;
            this.ActivityUser = ActivityUser;
            followB.setBackgroundResource(R.drawable.selector_button_follow_remove);
        }

        @Override
        public void onClick(View v) {

            Follow fl = new Follow(friendID);
            fl.setCallbackDeleteFollow(new onDeleteFollowerCompleted() {

                @Override
                public void Completed() {

                    followB.setBackgroundResource(R.drawable.selector_button_follow_add);
                    followB.setOnClickListener(new AddFollowerListener(friendID, followB, ActivityUser));
                    if (ActivityUser != null)
                        ActivityUser.updateFollowInfo(friendID);

                }
            });
            fl.execute(Follow.ACTION_DELETE);
        }
    }
}
